import { EventManager } from "../../Framework/Managers/EventManager";
import { GameEvent } from "../../Framework/Event/GameEvent";
import { FEvent } from "../../Framework/Event/FEvent";
import { GameDataManager } from "../../Framework/Managers/GameDataManager";
import {ReceiveData} from "../../Framework/Interfaces/Sockets/ReceiveData";
import { GameCommond } from "../Command/GameCommond";



export class LoginHandler{
    constructor(){
        this.addEvent()
    }

    private addEvent() : void {
        EventManager.addEvent(this, GameEvent.ON_LOGIN_MSGHANDLER, this.MsgHandler);
    }

    public removeEvent() : void {
        EventManager.removeEvent(this);
    }

    private MsgHandler(data:FEvent) : void {
        let d : ReceiveData = data.data
        switch (d.action) {
            case GameCommond.Game_Login:
                this.UpdatePlayerVO(d.data)
                EventManager.dispatchEventWith(GameEvent.ON_LOGIN_SUCCESS)
            break
        }   
    }


    private UpdatePlayerVO (d:PlayerVoInfo) {
        GameDataManager.game.fangka = d.Fangka
        GameDataManager.game.headurl = d.Headurl
        GameDataManager.game.nickname = d.Nickname
        GameDataManager.game.sex = d.Sex
        GameDataManager.game.deskno = d.Roomid
    }
}

interface PlayerVoInfo {
    Fangka: number
    Headurl: string
    Nickname: string
    Roomid: string
    Sex: number
    Uid: number
}